/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * frmPresentacion.java
 *
 * Created on 03-12-2014, 09:07:57 AM
 */
package ejerciciodeconjuntos;
/**
 *
 * @author Estudiante
 */
import Negocio.Entero;
import javax.swing.JOptionPane;
public class frmPresentacion extends javax.swing.JFrame {
    /** Creates new form frmPresentacion */
    public frmPresentacion() {
        initComponents();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGroup1 = new javax.swing.ButtonGroup();
        rbFactorial = new javax.swing.JRadioButton();
        rbPar = new javax.swing.JRadioButton();
        rbInvertir = new javax.swing.JRadioButton();
        rbCapicua = new javax.swing.JRadioButton();
        rbCantDig = new javax.swing.JRadioButton();
        rbCantPri = new javax.swing.JRadioButton();
        rbPrimo = new javax.swing.JRadioButton();
        rbCantPar = new javax.swing.JRadioButton();
        rbCantImpar = new javax.swing.JRadioButton();
        rbDigPri = new javax.swing.JRadioButton();
        rbPromPar = new javax.swing.JRadioButton();
        rbFibo = new javax.swing.JRadioButton();
        rbLiteral = new javax.swing.JRadioButton();
        txtn = new javax.swing.JTextField();
        btnOperar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtArea = new javax.swing.JTextArea();
        btnlinkVectores = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnGroup1.add(rbFactorial);
        rbFactorial.setText("factorial");

        btnGroup1.add(rbPar);
        rbPar.setText("es Par");

        btnGroup1.add(rbInvertir);
        rbInvertir.setText("Invertir");

        btnGroup1.add(rbCapicua);
        rbCapicua.setText("Capicua");

        btnGroup1.add(rbCantDig);
        rbCantDig.setText("Cantidad de digitos");

        btnGroup1.add(rbCantPri);
        rbCantPri.setText("Cantidad de Primos");

        btnGroup1.add(rbPrimo);
        rbPrimo.setText("Primo");

        btnGroup1.add(rbCantPar);
        rbCantPar.setText("Cantidad de par");

        btnGroup1.add(rbCantImpar);
        rbCantImpar.setText("Cantidad de Impar");

        btnGroup1.add(rbDigPri);
        rbDigPri.setText("Digitos Primos");

        btnGroup1.add(rbPromPar);
        rbPromPar.setText("Promedio de Pares");

        btnGroup1.add(rbFibo);
        rbFibo.setText("Fibonacci");

        btnGroup1.add(rbLiteral);
        rbLiteral.setText("Literal");

        txtn.setText("Inserte un número");
        txtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtnMouseClicked(evt);
            }
        });

        btnOperar.setText("Operar");
        btnOperar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOperarActionPerformed(evt);
            }
        });

        txtArea.setColumns(20);
        txtArea.setRows(5);
        jScrollPane1.setViewportView(txtArea);

        btnlinkVectores.setText("Vectores ->");
        btnlinkVectores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlinkVectoresActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtn, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbCantDig)
                    .addComponent(rbCapicua)
                    .addComponent(rbPar)
                    .addComponent(rbFactorial)
                    .addComponent(rbInvertir)
                    .addComponent(rbCantPri)
                    .addComponent(rbPromPar)
                    .addComponent(rbDigPri)
                    .addComponent(rbCantImpar)
                    .addComponent(rbCantPar)
                    .addComponent(rbPrimo)
                    .addComponent(rbLiteral)
                    .addComponent(rbFibo))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(btnOperar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 155, Short.MAX_VALUE)
                        .addComponent(btnlinkVectores)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(104, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(22, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnOperar)
                    .addComponent(btnlinkVectores))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rbFactorial)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbPar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbInvertir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbCapicua)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbCantDig)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbCantPri)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbPrimo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbCantPar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbCantImpar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbDigPri)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbPromPar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbFibo))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbLiteral)
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void txtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtnMouseClicked
        txtn.setText("");
    }//GEN-LAST:event_txtnMouseClicked
    private void btnOperarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOperarActionPerformed
        int n=0;
        try{
            Entero num = new Entero();
            num.setNum(Integer.parseInt(txtn.getText()));
            txtArea.setText("");
            if(rbFactorial.isSelected())            
                txtArea.setText(String.valueOf(num.factorial()));                                
            else if(rbPar.isSelected())
                txtArea.setText((num.par())?"Es Par el número "+txtn.getText():
                        txtn.getText()+" no es Par");
            else if(rbInvertir.isSelected())
                txtArea.setText(String.valueOf(num.invertir()));
            else if(rbCapicua.isSelected())
                txtArea.setText((num.capicua())?txtn.getText()+" es Capicua":
                        txtn.getText()+" no es Capicua");
            else if(rbCantDig.isSelected())
                txtArea.setText(String.valueOf(num.count()));
            else if(rbCantPri.isSelected())
                txtArea.setText(String.valueOf(num.cantidad_primos()));
            else if(rbPrimo.isSelected())
                txtArea.setText((num.primo(Integer.parseInt(txtn.getText())))?"Es Primo":"No es Primo");
            else if(rbCantPar.isSelected())
                txtArea.setText("Hay "+String.valueOf(num.catidad_par())+" números Pares");
            else if(rbCantImpar.isSelected())
                txtArea.setText("Hay "+String.valueOf(num.catidad_impar())+" números Inpares");
            else if(rbDigPri.isSelected())
                txtArea.setText(String.valueOf(num.digitos_primos()));
            else if(rbPromPar.isSelected())
                txtArea.setText("El Promedio de los Pares es: "+String.valueOf(num.promedio_pares()));
            else if(rbFibo.isSelected())
                txtArea.setText("Serie:\n"+num.fibonacci());
            else if(rbLiteral.isSelected())
                txtArea.setText("Falta... :-(");
            else JOptionPane.showConfirmDialog(null,
                  "Seleccione algun elemento para la oparacion");            
        }
        catch(Exception ex){
            txtArea.setText(ex.toString());
        }
    }//GEN-LAST:event_btnOperarActionPerformed
    private void btnlinkVectoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlinkVectoresActionPerformed
        // TODO add your handling code here:
        frmVectores frmv = new frmVectores();
        frmv.setVisible(true);
    }//GEN-LAST:event_btnlinkVectoresActionPerformed
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new frmPresentacion().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btnGroup1;
    private javax.swing.JButton btnOperar;
    private javax.swing.JButton btnlinkVectores;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton rbCantDig;
    private javax.swing.JRadioButton rbCantImpar;
    private javax.swing.JRadioButton rbCantPar;
    private javax.swing.JRadioButton rbCantPri;
    private javax.swing.JRadioButton rbCapicua;
    private javax.swing.JRadioButton rbDigPri;
    private javax.swing.JRadioButton rbFactorial;
    private javax.swing.JRadioButton rbFibo;
    private javax.swing.JRadioButton rbInvertir;
    private javax.swing.JRadioButton rbLiteral;
    private javax.swing.JRadioButton rbPar;
    private javax.swing.JRadioButton rbPrimo;
    private javax.swing.JRadioButton rbPromPar;
    private javax.swing.JTextArea txtArea;
    private javax.swing.JTextField txtn;
    // End of variables declaration//GEN-END:variables
}